//
//  NavBarTools.m
//  baodongPro
//
//  Created by feng on 16/8/19.
//  Copyright © 2016年 proper. All rights reserved.
//

#import "NavBarTools.h"
@interface NavBarTools()
{

}
@property (nonatomic,copy) rightBarButtonBlock rightBarBlock;

@end

@implementation NavBarTools
{



}

/**
 *      @author 冯宝东
 *
 *      用静态方法初始化
 *
 *      @return 一个工具实例
 */
+(instancetype)defaultTools
{
    return  [[self alloc] init];
}



/**
 *      @author 冯宝东
 *
 *      给导航设置默认的颜色(PS: 只有导航VC的第一个视图控制器调用一下就行了)
 */
-(void)settingNavBarColorWithCurrentController:(UIViewController*)currentVC
{
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithTitle:@"返回" style:UIBarButtonItemStylePlain target:nil action:nil];
    currentVC.navigationItem.backBarButtonItem = item;
    currentVC.navigationController.navigationBar.tintColor=[UIColor whiteColor];

}

/**
 *      @author 冯宝东
 *
 *      给导航条添加标题和右边TabBarItem
 */
-(void)settingNavBarTitle:(NSString*)title rightItem:(NSString*)rightTitle currentVC:(UIViewController*)currentVC
{
    //设置标题
    if (title)
    {
        currentVC.navigationItem.title=title;
    }
    
    if (!rightTitle)
    {
        return;
    }
    //设置右边按钮
    if ([rightTitle hasSuffix:@".png"])
    {
        UIBarButtonItem*rightBarItem=[[UIBarButtonItem alloc] initWithImage:[UIImage imageNamed:rightTitle] style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemPressed:)];
        currentVC.navigationItem.rightBarButtonItem=rightBarItem;
        
    }else if ([rightTitle isKindOfClass:[NSString class]])
    {
    
        UIBarButtonItem*rightBarItem=[[UIBarButtonItem alloc] initWithTitle:rightTitle style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemPressed:)];
        currentVC.navigationItem.rightBarButtonItem=rightBarItem;
    
    }
    

}


/**
 *      @author 冯宝东
 *
 *      给导航条添加标题和 多个右边TabBarItems
 */
-(void)settingNavBarTitle:(NSString*)title rightItems:(NSArray*)rightTitles currentVC:(UIViewController*)currentVC
{

    //设置标题
    if (title)
    {
        currentVC.navigationItem.title=title;

    }
    
    if (!rightTitles)
    {
        return;
    }
    NSMutableArray*produceRightItems=[NSMutableArray array];
    for (NSString*rightTitle in rightTitles)
    {
        
        UIBarButtonItem*rightBarItem=[[UIBarButtonItem alloc] initWithTitle:rightTitle style:UIBarButtonItemStylePlain target:self action:@selector(rightBarButtonItemPressed:)];
        [produceRightItems addObject:rightBarItem];
    }
    
    currentVC.navigationItem.rightBarButtonItems=produceRightItems;

}

/**
 *      @author 冯宝东
 *
 *      设置导航条的标题 和 右边按钮
 *
 *      @param title       标题
 *      @param rightTitle  右边按钮标题
 *      @param currentVC   当前视图控制器
 *      @param rightBlocks block回调
 */
-(void)settingNavBarTitle:(NSString*)title rightItem:(NSString*)rightTitle currentVC:(UIViewController*)currentVC rightItemBarAction:(rightBarButtonBlock)rightBlocks
{

    [self settingNavBarTitle:title rightItem:rightTitle currentVC:currentVC];
    self.rightBarBlock=[rightBlocks copy];
}


/**
 *      @author 冯宝东
 *
 *      设置导航条的标题 和 右边 N个 按钮
 *
 *      @param title       标题
 *      @param rightTitles  右边N个按钮标题
 *      @param currentVC   当前视图控制器
 *      @param rightBlocks block回调
 */
-(void)settingNavBarTitle:(NSString*)title rightItems:(NSArray*)rightTitles currentVC:(UIViewController*)currentVC rightItemBarAction:(rightBarButtonBlock)rightBlocks
{

    [self settingNavBarTitle:title rightItems:rightTitles currentVC:currentVC];
    self.rightBarBlock=[rightBlocks copy];

}


#pragma mark --------私有方法
-(void)rightBarButtonItemPressed:(UIBarButtonItem*)barItem
{
    if (self.rightBarBlock)
    {
        self.rightBarBlock(barItem);
    }
    
}




@end
